<?php
namespace app\index\validate;

use think\Validate;

class Member extends Validate
{
    protected $rule = [
	    ['phone','require','please enter your phone number'],
	    ['email','require|email','Please enter the email address|Your email address is not in the correct format, please enter again.'],
	    ['first_name','require','please enter your first_name'],
	    ['surnames','require','please enter your surnames'],
            ['date_of_birth','require|date','please enter your Date of Birth|Invalid format of Date of Birth'],
	    ['organization','require','Please enter an organization'],	
        
            ['addr1','require','Please enter an addr1'],
            ['city','require','Please enter a city'],
            ['country','require','please enter a country'],
        
            ['completion_date','require|date','please enter the completion_date|Incorrect format of completion_date'],
    ];

    protected $scene = [
        'edit1'  =>  ['first_name','surnames','date_of_birth','organization'],
        'edit2'  =>  ['phone','email'],
        'edit3'  =>  ['addr1','city','country'],
        'edit4'  =>  ['completion_date'],
    ]; 
     
     
     
    protected function is_tel($value){
        if($value){
            $exp = "/^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/";  
            $exp2 = "/^\d{3,4}-?\d{7,9}$/";  
            if(preg_match($exp,$value) || preg_match($exp2,$value)){  
                return true;  
            }else{  
                return 'Incorrect phone format';  
            }  
        }
    }
    
    
    protected function is_identity($value){
        if($value){
            $exp = "/^\d{6}((1[89])|(2\d))\d{2}((0\d)|(1[0-2]))((3[01])|([0-2]\d))\d{3}(\d|X)$/i";  
            if(preg_match($exp,$value)){  
                return true;  
            }else{  
                return '身份证格式不正确';  
            }  
        }
    }
     
}